package com.kwan.widget.indicator;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.List;


public class NavigatorAdapter extends CommonNavigatorAdapter {

    private final List<NavigatorEntity> mData;
    private NavigatorListener listener;

    public void setListener(NavigatorListener listener) {
        this.listener = listener;
    }

    public NavigatorAdapter(List<NavigatorEntity> mData,int selectedColor,int normalColor) {
        this.mData = mData;
		this.normalColor = normalColor;
		this.selectedColor = selectedColor;
    }


	public void addNavigatorEntity(NavigatorEntity entity){
		mData.add(entity);
		notifyDataSetChanged();
	}


	int selectedColor;
	int normalColor;

    @Override
    public int getCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public IPagerTitleView getTitleView(Context context, int index) {

		SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context);
    	simplePagerTitleView.setText(mData.get(index).getTitle());
        simplePagerTitleView.setTextSize(20);
        simplePagerTitleView.setNormalColor(normalColor);
        simplePagerTitleView.setSelectedColor(selectedColor);
        simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(index);
            }

        });

        return simplePagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        LinePagerIndicator indicator = new LinePagerIndicator(context);
        indicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
        indicator.setYOffset(UIUtil.dip2px(context, 0));
        indicator.setColors(Color.parseColor("#4BC986"));
        indicator.setRoundRadius(UIUtil.dip2px(context, 1));
        indicator.setLineHeight(UIUtil.dip2px(context, 6));

//		WrapPagerIndicator indicator = new WrapPagerIndicator(context);
//		indicator.setFillColor(Color.parseColor("#FFB940"));
        return indicator;
    }

    public interface NavigatorListener {
        void onClick(int index);
    }

}
